package com.self.structure;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class QueueMain {

    public static void main(String[] args) {

        testThreadPool();
    }

    private static void testThreadPool() {

        ThreadPoolExecutor executor =  new ThreadPoolExecutor(1,2,60,TimeUnit.SECONDS,new LinkedBlockingQueue<>(2000));


    }
}

interface TaskCallback {

    void onSuccess();

    void onFailure(Throwable throwable);
}

class MyRunnableTask implements Runnable {

    private TaskCallback taskCallback;
    private Runnable command;

    public MyRunnableTask(TaskCallback taskCallback,Runnable command) {
        this.taskCallback = taskCallback;
        this.command = command;
    }

    @Override
    public void run() {

        Throwable x = null;
        try {
            command.run();

        } catch (Exception e) {
            x = e;
        } finally {
            if(x != null) {
                taskCallback.onFailure(x);
            } else {
                taskCallback.onSuccess();
            }
        }
    }
}
